using System;
using System.Runtime.InteropServices;
using System.Text;

namespace EveSkillPocket
{
    public class Win32
    {
        [DllImport("coredll.dll")]
        internal static extern bool CeRunAppAtTime(string pwszAppName, ref SystemTime lpTime);
        public static IntPtr FindChildWindow(IntPtr root, string szClassName)
        {
            if (root != IntPtr.Zero)
            {
                StringBuilder lpClassName = new StringBuilder(0x100);
                GetClassName(root, lpClassName, 0xfe);
                if (lpClassName.ToString() == szClassName)
                {
                    return root;
                }
                IntPtr zero = IntPtr.Zero;
                for (zero = GetWindow(root, 5); zero != IntPtr.Zero; zero = GetWindow(zero, 2))
                {
                    IntPtr ptr2 = FindChildWindow(zero, szClassName);
                    if (ptr2 != IntPtr.Zero)
                    {
                        return ptr2;
                    }
                }
            }
            return IntPtr.Zero;
        }

        [DllImport("coredll.dll")]
        public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("coredll.dll", SetLastError = true)]
        public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
        [DllImport("coredll.dll")]
        public static extern IntPtr GetDesktopWindow();
        [DllImport("coredll.dll")]
        internal static extern IntPtr GetModuleHandle(string lpModuleName);
        [DllImport("coredll.dll")]
        public static extern IntPtr GetWindow(IntPtr hwnd, uint p);
        [DllImport("coredll.dll")]
        internal static extern IntPtr LoadIcon(IntPtr hInst, string IconName);
        [DllImport("coredll.dll")]
        public static extern int SendMessage(IntPtr hwnd, uint msg, uint wParam, COPYDATASTRUCT lParam);
        public static int VarPtr(object e)
        {
            GCHandle handle = GCHandle.Alloc(e, GCHandleType.Pinned);
            int num = handle.AddrOfPinnedObject().ToInt32();
            handle.Free();
            return num;
        }

        [StructLayout(LayoutKind.Sequential)]
        public class COPYDATASTRUCT
        {
            public int dwData;
            public int cbData;
            public int lpData;
        }

        [StructLayout(LayoutKind.Sequential)]
        public struct SystemTime
        {
            private short m_year;
            private short m_month;
            private short m_dayOfWeek;
            private short m_day;
            private short m_hour;
            private short m_minute;
            private short m_second;
            private short m_milliseconds;
            public static Win32.SystemTime Null
            {
                get
                {
                    Win32.SystemTime time = new Win32.SystemTime();
                    time.m_year = 0;
                    time.m_month = 0;
                    time.m_dayOfWeek = 0;
                    time.m_day = 0;
                    time.m_hour = 0;
                    time.m_minute = 0;
                    time.m_second = 0;
                    time.m_milliseconds = 0;
                    return time;
                }
            }
            public SystemTime(System.DateTime value)
            {
                this.m_year = (short)value.Year;
                this.m_month = (short)value.Month;
                this.m_dayOfWeek = (short)value.DayOfWeek;
                this.m_day = (short)value.Day;
                this.m_hour = (short)value.Hour;
                this.m_minute = (short)value.Minute;
                this.m_second = (short)value.Second;
                this.m_milliseconds = (short)value.Millisecond;
            }

            public override string ToString()
            {
                return string.Concat(new object[] { this.m_year, "-", this.m_month, "-", this.m_day, " ", this.m_hour, ":", this.m_minute, ":", this.m_second, ".", this.m_milliseconds });
            }

            public short Year
            {
                get
                {
                    return this.m_year;
                }
            }
            public short Month
            {
                get
                {
                    return this.m_month;
                }
            }
            public short DayOfWeek
            {
                get
                {
                    return this.m_dayOfWeek;
                }
            }
            public short Day
            {
                get
                {
                    return this.m_day;
                }
            }
            public short Hour
            {
                get
                {
                    return this.m_hour;
                }
            }
            public short Minute
            {
                get
                {
                    return this.m_minute;
                }
            }
            public short Second
            {
                get
                {
                    return this.m_minute;
                }
            }
            public short Milliseconds
            {
                get
                {
                    return this.m_milliseconds;
                }
            }
            public System.DateTime DateTime
            {
                get
                {
                    return this.ConvertToDateTime();
                }
                set
                {
                    this.ConvertFromDateTime(value);
                }
            }
            public int DayOfYear
            {
                get
                {
                    return this.DateTime.DayOfYear;
                }
            }
            public long Ticks
            {
                get
                {
                    return this.DateTime.Ticks;
                }
            }
            public TimeSpan TimeOfDay
            {
                get
                {
                    return this.DateTime.TimeOfDay;
                }
            }
            private void ConvertFromDateTime(System.DateTime value)
            {
                this.m_year = (short)value.Year;
                this.m_month = (short)value.Month;
                this.m_dayOfWeek = (short)value.DayOfWeek;
                this.m_day = (short)value.Day;
                this.m_hour = (short)value.Hour;
                this.m_minute = (short)value.Minute;
                this.m_second = (short)value.Second;
                this.m_milliseconds = (short)value.Millisecond;
            }

            private System.DateTime ConvertToDateTime()
            {
                return new System.DateTime(this.m_year, this.m_month, this.m_day, this.m_hour, this.m_minute, this.m_second);
            }
        }
    }
}
